Introduction to Linear Programming with Python - Part 3

Real world examples - Resourcing Problem

We'll now look at 2 more real world examples.

The first is a resourcing problem and the second is a blending problem.

Resourcing Problem

We're consulting for a boutique car manufacturer, producing luxury cars.

They run on one month (30 days) cycles, we have one cycle to show we can provide value.

There is one robot, 2 engineers and one detailer in the factory. The detailer has some holiday off, so only has 21 days available.

The 2 cars need different time with each resource:

Robot time: Car A - 3 days; Car B - 4 days.

Engineer time: Car A - 5 days; Car B - 6 days.

Detailer time: Car A - 1.5 days; Car B - 3 days.

Car A provides €30,000 profit, whilst Car B offers €45,000 profit.

At the moment, they produce 4 of each cars per month, for €300,000 profit. Not bad at all, but we think we can do better for them.

This can be modelled as follows:

Maximise

Profit = 30,000A + 45,000B

Subject to:

A ≥ 0

B ≥ 0

3A + 4B ≤ 30

5A + 6B ≤ 60

1.5A + 3B ≤ 21


In [1]:
import pulp

In [2]:
# Instantiate our problem class
model = pulp.LpProblem("Profit maximising problem", pulp.LpMaximize)

Unlike our previous problem, the decision variables in this case won't be continuous (We can't sell half a car!), so the category is integer.


In [3]:
A = pulp.LpVariable('A', lowBound=0, cat='Integer')
B = pulp.LpVariable('B', lowBound=0, cat='Integer')

In [4]:
# Objective function
model += 30000 * A + 45000 * B, "Profit"

# Constraints
model += 3 * A + 4 * B <= 30
model += 5 * A + 6 * B <= 60
model += 1.5 * A + 3 * B <= 21

In [5]:
# Solve our problem
model.solve()
pulp.LpStatus[model.status]


Out[5]:
'Optimal'

In [6]:
# Print our decision variable values
print "Production of Car A = {}".format(A.varValue)
print "Production of Car B = {}".format(B.varValue)


Production of Car A = 2.0
Production of Car B = 6.0

In [7]:
# Print our objective function value
print pulp.value(model.objective)


330000.0

So that's €330,000 monthly profit, compared to their original monthly profit of €300,000

By producing 2 cars of Car A and 4 cars of Car B, we bolster the profits at the factory by €30,000 per month.

We take our consultancy fee and leave the company with €360,000 extra profit for the factory every year.

In the next part, we'll be making some sausages!